//? 如何实现两个非常大的数字（已经超出了 Number 范围）的加法运算。注意由于这两个已经超过了 Number 范围
//? 答：用字符串

let a = "9007199254740991";
let b = "1234567899999999999";

function add(a ,b) {
    let lenb = b.length
    let lena = a.length
    let max = Math.max(lena,lenb)
    //? 补齐长度
    a = a.padStart(max, '0')
    b = b.padStart(max, '0')
    //? 从个位开始加
    let f = 0
    let t = 0
    let sum = ''
    for (let i = max - 1; i >= 0; i --) {
        t = parseInt(a[i]) + parseInt(b[i]) + f
        f = Math.floor(t / 10)
        sum = t % 10 + sum
    }
    if (f === 1) {
        sum = '1' + sum
    }
    return sum
}

console.log(add(a,b));
